/**
 * 获取年月日 星期 时分
 */
export function getDate() {
  let date = new Date();
  let year = date.getFullYear();
  let month =
    date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1;
  let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  let minutes =
    date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  let seconds =
    date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  let week = date.getDay();
  let weekStr = "";
  if (week == 0) {
    weekStr = "星期日";
  } else if (week == 1) {
    weekStr = "星期一";
  } else if (week == 2) {
    weekStr = "星期二";
  } else if (week == 3) {
    weekStr = "星期三";
  } else if (week == 4) {
    weekStr = "星期四";
  } else if (week == 5) {
    weekStr = "星期五";
  } else if (week == 6) {
    weekStr = "星期六";
  }
  return {
    date: year + "-" + month + "-" + day,
    time: hours + ":" + minutes + ":" + seconds,
    week: weekStr,
  };
}

export function getDateStr(isoString) {
  const date = new Date(isoString);
  // 提取年、月、日、小时、分钟和秒
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从0开始，需要加1，并确保是两位数
  const day = String(date.getDate()).padStart(2, "0"); // 确保是两位数
  const hours = String(date.getHours()).padStart(2, "0"); // 确保是两位数
  const minutes = String(date.getMinutes()).padStart(2, "0"); // 确保是两位数
  const seconds = String(date.getSeconds()).padStart(2, "0"); // 确保是两位数
  // 拼接成正常的日期格式
  const normalDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  return normalDate;
}
export function formatDuration(timestamp1, timestamp2) {
  // 计算差值（毫秒），取绝对值确保正数
  const diff = Math.abs(timestamp1 - timestamp2);

  // 转换为秒、分钟、小时
  const seconds = Math.floor(diff / 1000) % 60;
  const minutes = Math.floor(diff / (1000 * 60)) % 60;
  const hours = Math.floor(diff / (1000 * 60 * 60));

  // 补零（如 5 秒变成 "05"）
  const pad = (num) => num.toString().padStart(2, "0");

  return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
}
